package com.ikingtech.platform.service.authorization;

import com.ikingtech.framework.sdk.context.security.Me;
import com.ikingtech.framework.sdk.core.response.R;
import com.ikingtech.framework.sdk.web.annotation.ApiController;
import com.ikingtech.framework.sdk.web.annotation.PostRequest;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @author tie yan
 */
@RequiredArgsConstructor
@ApiController(value = "/authorization", name = "授权服务", description = "授权服务")
public class AuthorizationProcessor {

    private final AuthorizationService service;

    @PostRequest(order = 1, value = "/grant/id", summary = "用户授权(用户编号)", description = "用户授权(用户编号)，将指定用户数据权限信息缓存到Redis，用户每次请求时会从Redis获取数据权限信息。用户的数据权限根据用户所属角色的数据权限类型进行配置，并按菜单进行存储。")
    R<Object> grant(@Parameter(name = "id", description = "用户编号")
                    @RequestBody String id) {
        return R.ok(service.grant(id));
    }

    @PostRequest(order = 2, value = "/grant/login-user", summary = "用户授权(登录用户)", description = "用户授权(登录用户)，将当前登录用户数据权限信息缓存到Redis，用户每次请求时会从Redis获取数据权限信息。用户的数据权限根据用户所属角色的数据权限类型进行配置，并按菜单进行存储。")
    R<String> grantLoginUser() {
        return R.ok(service.grant(Me.id()));
    }

    R<Object> checkWrite() {
        return R.ok();
    }

    R<Object> checkRemove() {
        return R.ok();
    }

    R<Object> checkUpdate() {
        return R.ok();
    }

    R<Object> checkRead() {
        return R.ok();
    }

    R<List<String>> listQueryCode() {
        return R.ok();
    }
}
